package io.adrainty.bolee.framework.web.configuration;

import io.adrainty.bolee.framework.commons.properties.SecurityConfigProperties;
import io.adrainty.bolee.framework.web.interceptor.WebAuthInterceptor;
import jakarta.annotation.Resource;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <p>FrameworkMvcConfig</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description FrameworkMvcConfig
 * @since 2025/8/1 11:16:59
 */

@Configuration
@EnableConfigurationProperties({
        SecurityConfigProperties.class,
})
public class FrameworkSecurityConfig implements WebMvcConfigurer {

    @Resource
    private SecurityConfigProperties properties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(webAuthInterceptor(properties));
    }

    @Bean
    public WebAuthInterceptor webAuthInterceptor(SecurityConfigProperties properties) {
        return new WebAuthInterceptor(properties.getIgnoreUrl());
    }

}
